from flask import request

from apps.libs.redprint import Redprint
from apps.libs.token_auth import auth
from apps.models.level import Level

from apps.libs.error_code import ParameterException, NotFound, Success

api = Redprint('level')

@api.route('/levellist/', methods=['POST'])
@auth.login_required
def levelList():
    dance_id = request.json.get('dance_id', 0)
    if not dance_id:
        return ParameterException('缺少参数！')
    level_list = Level.query.filter_by(dance_id=dance_id).all()
    if not level_list:
        return NotFound()
    resp = [{'level_id': level.id, 'dance_id': level.dance_id, 'name': level.name, 'image': level.image, 'desc': level.desc} for level in level_list]
    return Success(data=resp)
